package com.zsrt.devbase.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zsrt.devbase.common.annotation.HandleEntity;
import com.zsrt.devbase.common.utils.ConstantDefine;
import com.zsrt.devbase.common.utils.ResponseVO;
import com.zsrt.devbase.common.utils.ShiroUtil;
import com.zsrt.devbase.dto.FunctionInfoDTO;
import com.zsrt.devbase.service.FunctionInfoService;

/** 
 * @author leixin  Email:leixin821792669@gmail.com
 * @date 2017年5月14日 上午11:04:05
 * @version 1.0
 */
@Controller
@RequestMapping(value="/function")
public class FunctionInfoController extends BaseAjaxController<FunctionInfoDTO>{

	@Autowired
	private FunctionInfoService functionInfoService;
	
	@Override
	public String init(Model model) {
		return "function/function";
	}
	
	@RequestMapping(value="/getFunctionListByRoleSession")
	@ResponseBody
	public ResponseVO getFunctionListByRoleSession() {
		ResponseVO vo = new ResponseVO();
		List<String> roleList = (List<String>) ShiroUtil.getSessionByKey(ConstantDefine.ROLE_SESSION);
		if (CollectionUtils.isEmpty(roleList)) {
			roleList = new ArrayList<>();
		}
		List<Object> list = functionInfoService.getFunctionListByRoleList(roleList);
		vo.setData(list);
		return vo;
		
	}
	
	@RequestMapping(value="/findByEntity")
	@ResponseBody
	public Map<String, Object> findByEntity(FunctionInfoDTO entity){
		Map<String, Object> result = functionInfoService.findByEntity(entity);
		return result;
	}
	@HandleEntity(fillCreator=true)
	@Override
	@ResponseBody
	public Object queryByEntity(FunctionInfoDTO entity) {
		List<FunctionInfoDTO> select = functionInfoService.select(null);
		return select;
	}
	
	@Override
	public ResponseEntity<Map<String, Object>> save(FunctionInfoDTO entity,BindingResult bindingResult) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public FunctionInfoDTO updateInit(String id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResponseEntity<Map<String, Object>> update(FunctionInfoDTO entity,
			BindingResult bindingResult) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResponseEntity<Map<String, Object>> delete(List<String> id) {
		// TODO Auto-generated method stub
		return null;
	}

	@RequestMapping(value = "/permissionInit")
	public String permissionInit() {
		return "permission/function";
	}
	
}
